package com.cy.pj.sys.controller;

import com.cy.pj.common.ShiroUtils;
import com.cy.pj.sys.entity.SysUser;
import com.cy.pj.sys.entity.SysUserMenu;
import com.cy.pj.sys.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 本Controller主要用于返回页面
 */
@Controller
public class PageController {
    @Autowired
    private SysMenuService sysMenuService;

    //@GetMapping("/menu/menu_list")
    //public String doMenuUI() {
    //    return "sys/menu_list";
    //}

    // 是上面的通用类型方法
    @GetMapping("/{module}/{moduleUI}")
    public String doUserUI(@PathVariable String moduleUI) {
        return "sys/" + moduleUI;
    }
    /**
     * localhost/doIndexUI
     *
     * 返回首页页面
     * @return
     */
    @RequestMapping("/doIndexUI")
    public String doIndexUI(Model model) {
        SysUser user = ShiroUtils.getUser();
        model.addAttribute("username", user.getUsername());
        List<SysUserMenu> userMenus = sysMenuService.findUserMenusByUserId(user.getId());
        model.addAttribute("userMenus", userMenus);
        return "starter";
    }

    /**
     * 返回分页控件页面
     * @return
     */
    @RequestMapping("/doPageUI")
    public String doPageUI() {
        return "common/page";
    }

    /**
     * 返回登录界面
     *
     * localhost/doLoginUI
     *
     * @return
     */
    @GetMapping("/doLoginUI")
    public String doLoginUI() {
        return "login";
    }
}
